package com.fms.controllers;

import home.HomePage;
import includes.Sessions;

import com.fms.dao.Form9_subDAO;
import com.fms.model.Form9_sub;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class Payroll_sub extends WebPage{
	
	private Model payroll_sub_idModel = new Model();
	private Model org_idModel = new Model();
	private Model activityModel = new Model();
	private Model payeeModel = new Model();
	private Model amountModel = new Model();
	private Model date_receivedModel = new Model();
	private Model uploaderModel = new Model();
	private Model date_createdModel = new Model();
	
	public Payroll_sub(){
		Form payroll_sub_Form = new Form ("payroll_sub_Form");
		
		TextField payroll_sub_id = new TextField("payroll_sub_id", payroll_sub_idModel);
		payroll_sub_id.setRequired(true);
		payroll_sub_Form.add(payroll_sub_id);
		
		TextField org_id = new TextField("org_id", org_idModel);
		org_id.setRequired(true);
		payroll_sub_Form.add(org_id);
		
		TextField activity = new TextField("activity", activityModel);
		activity.setRequired(true);
		payroll_sub_Form.add(activity);
		
		TextField payee = new TextField("payee", payeeModel);
		payee.setRequired(true);
		payroll_sub_Form.add(payee);
		
		TextField amount = new TextField("amount", amountModel);
		amount.setRequired(true);
		payroll_sub_Form.add(amount);
		
		TextField date_received = new TextField("date_received", date_receivedModel);
		date_received.setRequired(true);
		payroll_sub_Form.add(date_received);
		
		TextField uploader = new TextField("uploader", uploaderModel);
		uploader.setRequired(true);
		payroll_sub_Form.add(uploader);
		
		TextField date_created = new TextField("date_created", date_createdModel);
		date_created.setRequired(true);
		payroll_sub_Form.add(date_created);
		
		add(payroll_sub_Form);
		
		Button payroll_sub_form_add = new Button ("payroll_sub_form_add"){
			
			public void onSubmit(){
				
				String npayroll_sub_id= (String)payroll_sub_idModel.getObject();
				String norg_id= (String)org_idModel.getObject();
				String activity= (String)activityModel.getObject();
				String payee = (String)payeeModel.getObject();
				String amount = (String)amountModel.getObject();
				String date_received = (String)date_receivedModel.getObject();
				String uploader = (String)uploaderModel.getObject();
				String date_created = (String)date_createdModel.getObject();
				
				int payroll_sub_id = Integer.parseInt(npayroll_sub_id);
				int org_id = Integer.parseInt(norg_id);
				
				Form9_sub f9sub = new Form9_sub(payroll_sub_id, org_id, activity, payee, amount,
						date_received, uploader, date_created);
				
				Form9_subDAO f9subDAO = new Form9_subDAO();
				f9subDAO.insert(f9sub);
			}
		};
		
	}

}
